package cn.neusoft.service.impl;

import cn.neusoft.mapper.EmpMapper;
import cn.neusoft.query.EmpQuery;
import cn.neusoft.pojo.Emp;
import cn.neusoft.result.PageBean;
import cn.neusoft.service.IEmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class EmpService implements IEmpService {

    @Autowired
    EmpMapper empMapper;

    @Transactional
    @Override
    public int add(Emp emp) {
        return empMapper.add(emp);
    }

    @Transactional
    @Override
    public int update(Emp emp) {
        return empMapper.update(emp);
    }

    @Transactional
    @Override
    public int del(Integer empno) {
        return empMapper.del(empno);
    }

    @Transactional
    @Override
    public Emp getById(Integer empno) {
        return empMapper.getById(empno);
    }

    @Override
    public List<Emp> getAll() {
        return empMapper.getAll();
    }

    @Override
    public PageBean<Emp> getByPage(EmpQuery empQuery) {
        Page page = PageHelper.startPage(empQuery.getCurrentPage(), empQuery.getPageSize());
        empMapper.getByCondition(empQuery);
        PageBean<Emp> pageBean = new PageBean<>();
        pageBean.setTotal(page.getTotal());
        pageBean.setTotalPages(page.getPages());
        pageBean.setData(page.getResult());
        return pageBean;
    }
}
